package Controller;

import Model.SysInfo;
import Model.SysInfoType;
import Model.User;
import Service.SysInfoService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
//import jdk.internal.org.xml.sax.ErrorHandler;
import org.apache.ibatis.annotations.Param;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import utils.logUtils.LogSearch;
import utils.logUtils.PageDataResult;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/sysInfo")
@Controller
public class SysInfoController {
    private static final Logger logger = LoggerFactory.getLogger(RoleController.class);
    //调用service层
    @Resource
    SysInfoService sysInfoService;//实例化一个service


    //查询用户名
    @RequestMapping(value = "/findByOperator")
    @ResponseBody
    public  List<SysInfo> findByOperator(@RequestParam(value="user_id",required=false) String user_id, @RequestParam(value = "operTypeID",required = false)String operType,@RequestParam(value = "timeStart",required = false)String timeStart,@RequestParam(value = "timeEnd",required = false)String timeEnd) {
        System.out.println(user_id);
        System.out.println("操作类型"+ operType);
        List<SysInfo> sys = null;
        try {
            System.out.println("角色列表查询try" + sys);
            sys = sysInfoService.selectByOperator(user_id,operType,timeStart,timeEnd);
            System.out.println("角色列表查询" + sys);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("角色查询异常！", e);
        }
        System.out.println("角色列表：" + sys);
        return sys;
    }


//得到日志表格
    @RequestMapping(value = "/getAllLogList",produces ={"application/json;charset=UTF-8"})
    @ResponseBody
    public PageInfo getAllLogList(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "limit", defaultValue = "10") Integer limit){
        PageHelper.startPage(page, limit);
        List<SysInfo> sysInfos = sysInfoService.logList();
        PageInfo pdr = new PageInfo(sysInfos);
        return pdr;
    }

    //动态得到日志类型
    @RequestMapping(value = "/getAllLogType", method = RequestMethod.POST, produces ={"application/json;charset=UTF-8"})
    @ResponseBody
    public Map<String,Object> getAllLogType(){
        Map<String,Object> map = new HashMap<String,Object>();
        System.out.println("日志类型列表！");
        List<SysInfoType> getAllLogType = null;
        try {
            getAllLogType = sysInfoService. getAllLogType();
            System.out.println("角色列表查询=logTypeList:" + getAllLogType);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("角色查询异常！", e);
        }
        System.out.println("角色列表：" + getAllLogType);
        map.put("code",0);
        map.put("msg","");
        map.put("count",2000);
        map.put("data",getAllLogType);
        System.out.println("3222222" + JSON.toJSONString(map));
//        return JSON.toJSONString(map);
        return map;
    }

}
